package pl.agh.pp.zephyr.web.controlPanels;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.NoneScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import pl.agh.pp.zephyr.integration.GkController;
import pl.agh.pp.zephyr.integration.GkController.SimpleCommand;
import pl.agh.pp.zephyr.logic.Engine;

@ManagedBean(name = "gkControlPanel")
@NoneScoped
public class GkControlPanel implements ControlPanel{

	private static final long serialVersionUID = 1L;

	public static final String PARAM_NAME = "GkControlPanelCommand";
	
	private GkController controller;

	@ManagedProperty(value = "#{engine}")
	private Engine engine;
	
	public void command(ActionEvent a) {
		controller.commandSimple(SimpleCommand.valueOf(FacesContext.getCurrentInstance()
				  .getExternalContext().getRequestParameterMap()
				  .get(PARAM_NAME)));
	}

	public void destroy(ActionEvent a) {
		controller.destroy();
	}

	public void setController(GkController controller) {
		this.controller = controller;
	}

	public void setEngine(Engine engine) {
		this.engine = engine;
	}

	@Override
	public String getType() {
		return Type.GATEKEEPER.toString();
	}

}
